class TreeNode:
    def __init__(self, value):
        self.val = value
        self.left = None
        self.right = None


def build_tree(preorder, inorder):
    if not preorder or not inorder:
        return None

    root_val = preorder.pop(0)
    root = TreeNode(root_val)
    idx = inorder.index(root_val)

    root.left = build_tree(preorder, inorder[:idx])
    root.right = build_tree(preorder, inorder[idx + 1:])

    return root


def preorder_traversal(root):
    result = []
    if root:
        result.append(root.val)
        result += preorder_traversal(root.left)
        result += preorder_traversal(root.right)
    return result


def inorder_traversal(root):
    result = []
    if root:
        result += inorder_traversal(root.left)
        result.append(root.val)
        result += inorder_traversal(root.right)
    return result


def postorder_traversal(root):
    result = []
    if root:
        result += postorder_traversal(root.left)
        result += postorder_traversal(root.right)
        result.append(root.val)
    return result


# Example usage:
preorder = [1, 2, 4, 5, 3, 6, 7]
inorder = [4, 2, 5, 1, 6, 3, 7]

root = build_tree(preorder, inorder)

print("Preorder traversal:")
print(preorder_traversal(root))
print("\n")

print("Inorder traversal:")
print(inorder_traversal(root))
print("\n")

print("Postorder traversal:")
print(postorder_traversal(root))
print("\n")